<?php

/**
 * Created by PhpStorm.
 * User: xiao
 * Date: 2017/6/30
 * Time: 下午3:29
 */

namespace wordFilter;

/**
 * 敏感词过滤
 * Class WordFilter
 * @package wordFilter
 */
class WordFilter
{
    public function filter($content)
    {
        $filename = dirname(__FILE__).'/key.txt';

        if(!is_file($filename))return $content;

        $key = file_get_contents($filename);

        $badWord = explode('|', $key);
        $badWord =  array_combine($badWord,array_fill(0,count($badWord),'**'));

        $str = strtr($content, $badWord);

        return $str;
    }
}